package micropascalcomp;

import java.util.*;

/**
 * Class for a individual symbol table and its methods.
 * @author Jason Welch, Codi Gann, Jamal Martin
 */
public class SymbolTable {
    private String name;
    private ArrayList<SymbolTableEntry> table;
    
    public SymbolTable(String name){
        this.name = name;
        table = new ArrayList<SymbolTableEntry>();
    }
    
    public void add(String lexeme,String kind, String type){
        table.add(new SymbolTableEntry(lexeme, kind, type));
    }
    
    public void add(String lexeme, String kind, String type, String mode){
        table.add(new SymbolTableEntry(lexeme, kind, type, mode));
    }
    
    public SymbolTableEntry getEntry(String lexeme){
        for(int i = 0; i < table.size(); i++){
            if (table.get(i).compare(lexeme)){
                return table.get(i);
            }
        }
        return null;
    }
    
    public int has(String lexeme){
        for(int i = 0; i < table.size(); i++){
            if (table.get(i).compare(lexeme)){
                return i;
            }
        }
        return -1;
    }
    
    public int getSize(){
        return table.size();
    }
    
    /*
     * Method that prints the table
     */
    public void printTable(){
        System.out.println("Symbol Table for: " + name);
        for(int i = 0; i < table.size(); i++){
            table.get(i).print();
            System.out.print(" " + i + "\n");
        }
    }
}
